package com.zhuchaooasystem.adapter.holder;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zhuchaooasystem.R;
import com.zhuchaooasystem.entity.AudioInfo;
import com.zhuchaooasystem.ui.home.fragment.oa.record.RecordActivity;

/**
 * @author yinsi
 */
public class RecordUploadHolder extends BaseViewHolder<AudioInfo> {
    private RelativeLayout rootView;
    private TextView tv_path;
    private TextView tv_time;
    private ImageView iv_delete;
    private ImageView iv_control;
    private int position;
    //----
    private RecordActivity activity;

    public RecordUploadHolder(ViewGroup parent, RecordActivity activity) {
        super(parent, R.layout.item_activity_record_vp_record);
        this.activity = activity;
        //----
        rootView = $(R.id.item_activity_record_vp_record_relative_root);
        tv_path = $(R.id.item_activity_record_vp_record_tv_path);
        tv_time = $(R.id.item_activity_record_vp_record_tv_time);
        iv_delete = $(R.id.item_activity_record_vp_record_iv_delete);
        iv_control = $(R.id.item_activity_record_vp_record_iv_control);
    }

    @Override
    public void setData(final AudioInfo audio) {
        Log.i("ViewHolder", "position" + getDataPosition());
        int cur_position = activity.getCur_position();
        boolean showDelete = activity.isShowDelete();
        position = getDataPosition();
        //----
        //该音乐正在播放
        if (cur_position == position) {
            iv_control.setImageResource(R.drawable.ic_record_stop);
        } else {
            iv_control.setImageResource(R.drawable.ic_record_play);
        }
        //----
        tv_path.setText(audio.getFilePath().substring(audio.getFilePath().lastIndexOf("/") + 1));
        tv_time.setText("录音总时长 " + audio.getOften());
        if (!showDelete) {
            iv_delete.setVisibility(View.GONE);
        } else {
            iv_delete.setVisibility(View.VISIBLE);
        }
        //----
        iv_control.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                activity.onClickPlay(position);
            }
        });
        //----
        iv_delete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                activity.onClickDelete(position);
            }
        });
        //----
        rootView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View view) {
                activity.onLongClick(position);
                return false;
            }

        });


    }

}
